<script lang="ts">
export default {
  name: 'LoginComponent',
}
</script>
<script setup lang="ts">
import {reactive} from "vue";
import {Lock, User} from "@element-plus/icons-vue";
import {ElMessage} from "element-plus";
import {post} from "@/net";
import router from "@/router";
import {useCookies} from "vue3-cookies";

const cookies = useCookies().cookies;

const userForm = reactive({
      username: '',
      password: '',
      remember: false,
    }
)

const login = () => {
  if (!userForm.username || !userForm.password) {
    ElMessage.warning('请填写用户名和密码!')
  } else {

    post('api/auth/login', {
          username: userForm.username,
          password: userForm.password,
          remember: userForm.remember,
        }
        , (data: string) => {
          if (userForm.remember === true) {

          }
          console.log(userForm);
          ElMessage.success(data);
          router.push('/home');
        }, (data: string) => {
          ElMessage.error(data);
        })
  }
}
const handleRegistration = () => {

  router.push('/register');
}

const fotgot_pw = () => {
  ElMessage.error('忘记密码,请和社区管理员联系修改');
}

const rememberMe = () => {
}

</script>

<template>

  <div class="login-box">
    <h1>社区管理</h1>
    <div class="login">
      <!-- 登录框左侧 -->
      <div class="login-left">
        <div class="login-input-box">
          <h2 class="login-input-box-h2">登录</h2>
          <!--   登录输入框   -->
          <el-input class="el_input_Box" type="text" size="large" v-model="userForm.username" placeholder="账号名/邮箱" id="test_username">
            <template #prefix>
              <el-icon>
                <User/>
              </el-icon>
            </template>
          </el-input>
          <br>
          <el-input class="el_input_Box" type="password" size="large"
                    v-model="userForm.password"
                    placeholder="请输入密码" show-password id="test_password">
            <template #prefix>
              <el-icon>
                <Lock/>
              </el-icon>
            </template>
          </el-input>
          <!--        -->
          <div>
            <el-checkbox id="remember_me">记住我</el-checkbox>
          </div>
          <div>
            <el-button id="login_button" @click="login" type="success" plain>登录</el-button>
          </div>
          <div class="tips-box">
            <div class="tips">
              <el-link style="" @click="fotgot_pw">忘记密码</el-link>
            </div>
            <div class="tips">
              <el-link @click="handleRegistration" id="register_user">还没有账号？<span style="color: #337ecc">点击注册</span></el-link>
            </div>
          </div>
        </div>
      </div>
      <!--登录框右侧-->

      <div class="login-right">
        <div class="login-logo-box">
          <p class="login-logo-box-p">准备开始新的一天，</p>
          <p class="login-logo-box-p" style="text-indent: 1em;">与您的同伴们一起来</p>
          <p class="login-logo-box-p" style="text-indent: 2em;">创造、分享和探索吧。</p>
        </div>
      </div>

    </div>
  </div>
</template>

<style scoped>

h1 {
  color: black;
  font-size: 30px;
}

.login-box {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  flex-direction: column;
}

.login {
  border-radius: 10px;
  display: flex;
  align-items: center;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
  overflow: hidden;
  width: 40vw;
  max-height: 60vh;
  min-height: 50vh;
  max-width: 100%;
  margin-top: 100px;
  backdrop-filter: blur(8px);
}

.login-left {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 2px solid black;
}

.login-right {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.login-input-box {
  margin-left: 30px;
  margin-right: 30px;
}

.login-input-box-h2 {
  margin-top: 0;
  text-align: center;
  font-size: 30px;
}

.el_input_Box {
  display: flex;
  align-items: center;
  justify-content: center;
}


.login-logo-box {
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  width: 100%;
  margin-top: 20vh;
}

.login-logo-box-p {
  font-size: 24px;
  margin-top: 20px;
  margin-left: 20px;
  text-align: left;
}

#remember_me {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  width: 100%;
}

#login_button {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  width: 70%;
  margin: auto;
  border-radius: 20px 20px 20px 20px;
}

.tips-box {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: row;
  width: 100%;
  text-align: center;
}

</style>